<?php

require_once('Interface.php');

class CodeIslands_Island_Generator_Php implements CodeIslands_Island_Generator_Interface
{
	public function getIsland($parameters)
	{
		$name = $parameters['name'];
		
		$paramArrayString = '';
		foreach($parameters as $key => $param)
			$paramArrayString .= "'{$key}' => '{$param}',";
		
		switch($name) 
		{
			case 'Api':
				$code = "<?php\n" . 
					"define('APPLICATION_PATH', '" . PRODUCTION_APPLICATION_PATH . "');\n" .
					"define('ISLAND_PLUGINS_PATH', '" . PRODUCTION_ISLAND_PLUGINS_PATH . "');\n" . 
					"define('ISLANDS_PATH', '" . PRODUCTION_ISLANDS_PATH . "');\n\n" .
					"require_once(ISLAND_PLUGINS_PATH . '/Api/Api.php');\n\n" .
					'$api = new Api();' . "\n?>\n";
				break;
			default:
				$code = "<?php\n" .
					'$island = $api->getIsland(' . "'$name');\n" .
					'echo $island->getContent(array(' . $paramArrayString . '));' . "\n" .
					"?>\n";
				break;
		}
		
		return $code;
	}
}